# Maintainer: ImperatorS79 <fevrier.simon@gmail.com>

_realname=nodeeditor
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.3
pkgrel=1
pkgdesc="NodeEditor is conceived as a general-purpose Qt-based library aimed at graph-controlled data processing."
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/paceholder/nodeeditor"
license=("BSD-3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt5-base")    
source=(https://github.com/paceholder/nodeeditor/archive/refs/tags/${pkgver}.tar.gz
        0001-fix-struct-std-hash-qstring.patch
        0002-install-dll.patch)
sha256sums=('4e3194a04ac4a2a2bf4bc8eb6cc27d5cc154923143c1ecf579ce7f0115a90585'
            '1fae5e60fcb1a86de6722e1caddc6a5d2b26843fdcea761176e1e2fa1fdd3c99'
            '2acdeb0d923686713053185ce0f2d7ffd4a04d3bcace757987307029e93a022e')

prepare() {
  cd "${srcdir}/nodeeditor-${pkgver}"

  patch -p1 -i "${srcdir}/0001-fix-struct-std-hash-qstring.patch"
  patch -p1 -i "${srcdir}/0002-install-dll.patch"
}

build() { 
  [[ -d ${srcdir}/build-${MINGW_CHOST}-shared ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}-shared
  mkdir ${srcdir}/build-${MINGW_CHOST}-shared && cd ${srcdir}/build-${MINGW_CHOST}-shared
    
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
	  -DBUILD_TESTING=OFF \
      -DBUILD_SHARED_LIBS=ON ../nodeeditor-${pkgver}
  
  ${MINGW_PREFIX}/bin/cmake --build .
  
  [[ -d ${srcdir}/build-${MINGW_CHOST}-static ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}-static
  mkdir ${srcdir}/build-${MINGW_CHOST}-static && cd ${srcdir}/build-${MINGW_CHOST}-static
    
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
	  -DBUILD_TESTING=OFF \
	  -DBUILD_EXAMPLES=OFF \
      -DBUILD_SHARED_LIBS=OFF ../nodeeditor-${pkgver}
  
  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
  
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
}
